#ifndef OVERLAY_H
#define OBERLAY_H

#define __STDC_LIMIT_MACROS
#include <stdint.h>

extern "C" { 
#include <libavformat/avformat.h>
#include <libavfilter/avfiltergraph.h>
#include <libavfilter/avcodec.h>
#include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>
#include <libavutil/avstring.h>
#include <libswresample/swresample.h>
#include <libavutil/opt.h>
#include <libavutil/audio_fifo.h>
}
#include <dirent.h>

#ifndef WINDOWS
#include <time.h>
#endif

#include <vector>
#include <iostream>
#include <string.h>
#include <sstream>
#include <stdlib.h>

//maximum path length
#define PATH_LEN 128

struct AudioContext {
	const AVClass *av_class;
	AVFormatContext *in_fmt;
	AVCodecContext *dec_ctx;
	AVCodecContext *enc_ctx;
	struct SwrContext *swr_ctx;
	char fname[128];
	AVFrame *dec_frame;
	AVPacket dec_pkt;
	double time;

	AVAudioFifo *fifo;

};

struct DrawContext {
	const AVClass *av_class;
	const char *text;
	int text_len;
// -1 means position automatically set to centre
	int xpos;
	int ypos;
	int color;
	int shadowcolor;
	int shadowx;
	int shadowy;


};
struct GeneratorCtx {

	const AVClass *av_class;
	AVFormatContext *vfmt;


	AVFormatContext *oc;
	AVFilterGraph *filter_graph;
	AVFilterContext *buffersink;
	AVFilterContext *buffersrc;
	AVCodecContext *dec_ctx;
	AVFrame *InFrame;
	AVFrame *OutFrame;
	int cur_pts;
	double ptime;
	int audio_stream_index;
	int audio_pkt_size;
	struct AudioContext audio;
	struct DrawContext draw;
	char *vg_install_path;

};

typedef struct GeneratorCtx *(*init_generator_t)(const char* oname);
extern "C" struct GeneratorCtx *init_generator(const char* oname);

typedef void (*dinit_generator_t)(struct GeneratorCtx *ctx);
extern "C" void dinit_generator(struct GeneratorCtx*ctx);


typedef int (*add_phase_t)(struct GeneratorCtx *ctx, const char*img_directory,
		const char*overlay_text, int img_count, int min_time, int max_time,
		int textcolor, int textx,int texty,int shadowcolor,
		int shadowx,int shadowy);


extern "C" int add_phase(struct GeneratorCtx *ctx, const char*img_directory,
		const char*overlay_text, int img_count, int min_time, int max_time,
		int textcolor, int textx,int texty,int shadowcolor,
		int shadowx,int shadowy);



typedef int (*set_audio_t)(struct GeneratorCtx *ctx, const char*audio_file);
extern "C" int set_audio(struct GeneratorCtx *ctx, const char*audio_file);

#endif
